package crm.system.dao.basddao.impl;

import java.math.BigDecimal;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import crm.system.dao.basddao.BasdDao;
import crm.system.entity.BasDict;

public class BasdDaoImpl extends HibernateDaoSupport implements BasdDao {

	@Override
	/**
	 * 获取总记录
	 * @param dc
	 * @return Integer count
	 */
	public Integer getTotalCount(DetachedCriteria dc) {
		int count = this.getHibernateTemplate().find("from BasDict").size();
		if (count != 0) {
			return count;
		} else {
			return 0;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	/**
	 * 分页查询
	 * @param dc
	 * @param fistResult
	 * @param maxResult
	 * @return list列表
	 */
	public List<BasDict> getPageList(DetachedCriteria dc, int firstResult,
			int maxResult) {
		List<BasDict> basdList = this.getHibernateTemplate().findByCriteria(dc,
				firstResult, maxResult);
		if (basdList.size() == 0) {
			return null;
		} else {
			return basdList;
		}

	}

	@Override
	/**
	 * 获取总记录
	 * @param dc
	 * @return Integer count
	 */
	public BasDict getById(Long id) {
		BasDict basdDict = null;
		try {
			basdDict = this.getHibernateTemplate().get(BasDict.class, id);
		} catch (DataAccessException e) {
			e.printStackTrace();
		}
		return basdDict;
	}

	@Override
	/**
	 * 修改数据字典
	 * @param basdDict
	 * @return true 成功  false 失败
	 */
	public boolean update(BasDict basdDict) {
		try {
			this.getHibernateTemplate().update(basdDict);
			return true;
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}

	@Override
	/**
	 * 删除方法
	 * @param id
	 * @return  boolean 类型的值
	 */
	public boolean delete(Long id) {
		BasDict basDict=null;
		try {
			basDict=this.getHibernateTemplate().get(BasDict.class, id);
			this.getHibernateTemplate().delete(basDict);
			return true;
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	}

	@Override
	/**
	 * 添加方法
	 * @param basDict
	 * @return
	 */
	public boolean add(BasDict basDict) {
		try {
			this.getHibernateTemplate().save(basDict);
			return true;
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	}

}
